package com.shanzmoo.admin.web.trade;

import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.base.bean.SResponse;
import com.shanzmoo.core.domain.pay.PayOrderEntityLocalUtil;
import com.shanzmoo.core.domain.pay.PayOrderQrCodeReq;
import com.shanzmoo.core.domain.pay.PayOrderTradeReq;
import com.shanzmoo.core.service.ITradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 交易服务
 * @author Gzhao 2021/1/2
 */
@Slf4j
@RestController
@RequestMapping("trade")
@Api(tags = "支付交易")
public class TradeController {

    @Autowired
    private ITradeService tradeService;

    @ApiOperation("获取付款二维码")
    @PostMapping("getQrCode")
    public SHttpResponse<String> genQrCode(@Valid @RequestBody PayOrderQrCodeReq request) {
        SResponse<String> re = tradeService.genQrCode(request);

        PayOrderEntityLocalUtil.clear();
        return SHttpResponse.transform(re);
    }

    @ApiOperation("扫描用户的付款码，收款")
    @PostMapping("payByQrCode")
    public SHttpResponse<Boolean> tradeByQrCode(@RequestBody PayOrderTradeReq request) {
        SResponse<Boolean> re = tradeService.tradeByQrCode(request);

        PayOrderEntityLocalUtil.clear();
        return SHttpResponse.transform(re);
    }


}
